package huawei.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources.Theme;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View.BaseSavedState;
import android.widget.FrameLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.Locale;
import o.fo;
import o.fqd.a;
import o.fqd.b;
import o.fqd.c;
import o.fqd.d;
import o.fqd.g;
import o.fqd.i;
import o.fqd.j;
import o.gg;

public class HwDownLoadWidget extends FrameLayout {
    private LayerDrawable ʻ;
    public ColorStateList ʼ;
    public Drawable ʽ;
    private ProgressBar ˊ;
    private String ˋ;
    private int ˎ;
    private int ˏ;
    private TextView ॱ;
    private boolean ॱॱ;
    public ColorStateList ᐝ;

    static class SavedState extends BaseSavedState {
        public static final Creator<SavedState> CREATOR = new Creator<SavedState>() {
            public /* synthetic */ Object createFromParcel(Parcel parcel) {
                return ˋ(parcel);
            }

            public /* synthetic */ Object[] newArray(int i) {
                return ॱ(i);
            }

            public SavedState ˋ(Parcel parcel) {
                return new SavedState(parcel);
            }

            public SavedState[] ॱ(int i) {
                return new SavedState[i];
            }
        };
        int ˎ;
        int ˏ;

        SavedState(Parcelable parcelable) {
            super(parcelable);
        }

        private SavedState(Parcel parcel) {
            super(parcel);
            this.ˎ = parcel.readInt();
            this.ˏ = parcel.readInt();
        }

        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            if (parcel == null) {
                Log.w("DownLoadWidget", "writeToParcel, parcel is null");
                return;
            }
            parcel.writeInt(this.ˎ);
            parcel.writeInt(this.ˏ);
        }
    }

    public HwDownLoadWidget(Context context) {
        this(context, null);
    }

    public HwDownLoadWidget(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public HwDownLoadWidget(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.ˊ = null;
        this.ॱ = null;
        this.ˏ = 0;
        this.ॱॱ = true;
        ˏ(context, attributeSet);
    }

    private void ˏ(Context context, AttributeSet attributeSet) {
        ((LayoutInflater) getContext().getSystemService("layout_inflater")).inflate(j.ˏ, this, true);
        this.ˊ = (ProgressBar) findViewById(d.ˋ);
        this.ॱ = (TextView) findViewById(d.ˏ);
        this.ˎ = c.ˏ;
        Drawable ˊ = fo.ˊ(context, c.ˎ);
        gg.ॱ(gg.ʻ(fo.ˊ(context, c.ˊ)).mutate(), fo.ˋ(context, a.ˋ));
        this.ʻ = new LayerDrawable(new Drawable[]{r1, ˊ});
        this.ˋ = "";
        Theme theme = context.getTheme();
        if (theme != null) {
            TypedArray obtainStyledAttributes = theme.obtainStyledAttributes(attributeSet, i.ˊˋ, b.ˋ, g.ˏ);
            if (obtainStyledAttributes != null) {
                this.ʽ = obtainStyledAttributes.getDrawable(i.ˉ);
                this.ˊ.setProgressDrawable(this.ʽ);
                this.ॱॱ = obtainStyledAttributes.getBoolean(i.ˋᐝ, true);
                if (this.ॱॱ) {
                    this.ˊ.setProgressDrawable(this.ʻ);
                }
                this.ᐝ = obtainStyledAttributes.getColorStateList(i.ˊˊ);
                this.ʼ = obtainStyledAttributes.getColorStateList(i.ˌ);
                this.ॱ.setTextColor(this.ᐝ);
                obtainStyledAttributes.recycle();
            }
        }
    }

    public void setIdleText(String str) {
        if (str == null) {
            Log.w("DownLoadWidget", "setIdleText, idleText is null");
        } else if (this.ˏ != 0) {
            Log.w("DownLoadWidget", "setIdleText, mState = " + this.ˏ);
        } else {
            this.ॱ.setText(str);
        }
    }

    public void setPauseText(String str) {
        if (str == null) {
            Log.w("DownLoadWidget", "setPauseText, pauseText is null");
        } else {
            this.ˋ = str;
        }
    }

    public void ai_() {
        this.ˊ.setBackground(null);
        if (this.ॱॱ) {
            this.ˊ.setProgressDrawable(this.ʻ);
        } else {
            this.ˊ.setProgressDrawable(this.ʽ);
        }
        this.ॱ.setTextColor(this.ᐝ);
        this.ˏ = 0;
    }

    public void setProgress(int i) {
        this.ˊ.setProgress(i);
    }

    public int ॱˊ() {
        return this.ˏ;
    }

    public void ˏ(int i) {
        if (this.ˊ == null) {
            Log.w("DownLoadWidget", "incrementProgressBy, mDownLoadProgress is null");
            return;
        }
        if (this.ˏ != 1) {
            this.ˏ = 1;
            this.ˊ.setBackground(null);
            this.ˊ.setProgressDrawable(fo.ˊ(getContext(), this.ˎ));
            this.ॱ.setTextColor(this.ʼ);
        }
        this.ˊ.incrementProgressBy(i);
        ˋ(this.ˊ.getProgress());
    }

    private void ˋ(int i) {
        if (this.ॱ == null) {
            Log.w("DownLoadWidget", "setPercentage, mPercentage is null");
        } else if (this.ˏ == 2) {
            this.ॱ.setText(this.ˋ);
        } else {
            this.ॱ.setText(String.format(Locale.getDefault(), "%2d", new Object[]{Integer.valueOf(i)}) + "%");
        }
    }

    public Parcelable onSaveInstanceState() {
        Parcelable savedState = new SavedState(super.onSaveInstanceState());
        Log.w("HwDownload", "onSaveInstanceState");
        savedState.ˎ = this.ˊ.getProgress();
        savedState.ˏ = this.ˏ;
        return savedState;
    }

    public void onRestoreInstanceState(Parcelable parcelable) {
        if (parcelable instanceof SavedState) {
            SavedState savedState = (SavedState) parcelable;
            super.onRestoreInstanceState(savedState.getSuperState());
            this.ˏ = savedState.ˏ;
            if (this.ˏ == 0 || this.ˊ == null) {
                Log.w("DownLoadWidget", "onRestoreInstanceState mState = " + this.ˏ + " , mDownLoadProgress = " + this.ˊ);
                return;
            }
            this.ˊ.setProgressDrawable(fo.ˊ(getContext(), c.ˏ));
            this.ॱ.setTextColor(this.ʼ);
            return;
        }
        Log.w("DownLoadWidget", "onRestoreInstanceState, state = " + parcelable);
    }

    public ProgressBar ˏॱ() {
        return this.ˊ;
    }

    public TextView ˊॱ() {
        return this.ॱ;
    }
}
